package SetDemo.TreeSetSemo.demo1;

public class Student implements Comparable<Student>{
    private String name;
    private int age;
    private int ChineseScore;
    private int MathScore;
    private int EglishScore;
    
    public Student() {
    }
    

    public Student(String name, int age, int chineseScore, int mathScore, int eglishScore) {
        this.name = name;
        this.age = age;
        ChineseScore = chineseScore;
        MathScore = mathScore;
        EglishScore = eglishScore;
    }


    /**
     * @return String return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @return int return the age
     */
    public int getAge() {
        return age;
    }

    /**
     * @param age the age to set
     */
    public void setAge(int age) {
        this.age = age;
    }


    /**
     * @return int return the ChineseScore
     */
    public int getChineseScore() {
        return ChineseScore;
    }

    /**
     * @param ChineseScore the ChineseScore to set
     */
    public void setChineseScore(int ChineseScore) {
        this.ChineseScore = ChineseScore;
    }

    /**
     * @return int return the MathScore
     */
    public int getMathScore() {
        return MathScore;
    }

    /**
     * @param MathScore the MathScore to set
     */
    public void setMathScore(int MathScore) {
        this.MathScore = MathScore;
    }

    /**
     * @return int return the EglishScore
     */
    public int getEglishScore() {
        return EglishScore;
    }

    /**
     * @param EglishScore the EglishScore to set
     */
    public void setEglishScore(int EglishScore) {
        this.EglishScore = EglishScore;
    }
    // 获取当前学生的总分
    public int getSum(){
        return (this.getChineseScore() + this.getEglishScore() + this.getMathScore());
    }

    


    @Override
    public int compareTo(Student o) {
        // 比较当前学生和另一个学生的总分
        int i = this.getSum() - o.getSum();
        // 如果总分相等，再比较语文成绩
        i = i == 0 ? this.getChineseScore() - o.getChineseScore() : i;
        // 如果语文成绩一样，比较数学成绩
        i = i == 0 ? this.getMathScore() - o.getMathScore() : i;
        // 如果数学成绩也一样则比较英语成绩
        i = i == 0 ? this.getEglishScore() - o.getEglishScore() : i;
        // 如果英语成绩也一样，则比较年龄
        i = i == 0 ? this.getAge() - o.getAge() : i;
        // 如果年龄一样则按照姓名的字母顺序排
        i = i == 0 ? this.getName().compareTo(o.getName()) : i;
        return i;
    }
    // 获取全部信息
    public void show(){
        System.out.println("姓名：" + this.getName() + "， 总分： " + this.getSum() + "分， 年龄： " + this.getAge() + "， 语文成绩： " + this.getChineseScore() + "分， 数学成绩：" + this.getMathScore() + "分， 英语成绩： " + this.getEglishScore() + "分");
    }

}
